<?php
/**
 * 关于我们
 * Create by PhpStorm
 * User: lijia
 * Data: 2020/8/7
 * Time: 15:12
 */

namespace app\admin\controller;

use app\admin\business\MessageBus;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;
class About extends Common
{
    public function __construct()
    {
        parent::__construct();
    }


    public function index(){
        if (Request::isPost()) {
            $list = Db::name('page')->where('id',1)->paginate(array('list_rows' => 1, 'page' => 1))
                ->toArray();
            return $result = ['code' => 0, 'msg' => '获取成功!', 'data' => $list['data'], 'count' => $list['total'], 'rel' => 1];
        }
        return View::fetch();
    }


    /**
     * @return array|string
     * @throws \Exception
     */
    public function edit(){
        if (Request::isPost()){
            $post = input('post.');
            $data = [
                'content' => $post['content']
            ];
            $res =  Db::name('page')->where('id',1)->update($data);
            if ($res){
                return ['code' => 0, 'msg' => '操作成功!'];
            }else{
                return ['code' => 3000, 'msg' => '操作失败'];
            }
        }else{
            $info = Db::name('page')->where('id',1)->find();
            $this->assign('info', $info);
            return View::fetch();
        }
    }


}